set matsize 11000 
 
* ) Insert directory
cd ""
use "Paper-referee level data", clear

***************************************
global authorcontrols avg* numAuthors

sum $authorcontrols

* ) Top-coding distance and include missing
replace referee_distance_min = 6 if referee_distance_min>6 | referee_distance_min==.
replace editor_distance_min = 6 if editor_distance_min>6 | editor_distance_min==.

*) When doing editor analysis, don't double count observations due to referee assignment
bysort ms_number_id editor_id: gen indicate = 1 if _n==1

**************
**************
**************
*Employment and PhD
eststo clear
*Editor - Connectivity
eststo: reghdfe passed_the_desk editor_phdmatch_max $authorcontrols if indicate==1, absorb(editor_id) vce(cluster ms_number_id)
estadd local refFE "X",replace
estadd local paperFE " ",replace
estadd local authorcontrols "X",replace
*Editor - Connectivity
eststo: reghdfe passed_the_desk editor_employmentmatch_max $authorcontrols if indicate==1, absorb(editor_id) vce(cluster ms_number_id)
estadd local refFE "X",replace
estadd local paperFE " ",replace
estadd local authorcontrols "X",replace
*NBER program match
eststo: reghdfe passed_the_desk editor_isnbermatch_program_max $authorcontrols if indicate==1, absorb(editor_id) vce(cluster ms_number_id)
estadd local refFE "X",replace
estadd local paperFE " ",replace
estadd local authorcontrols "X",replace
*Editor - Connectivity
eststo: reghdfe passed_the_desk editor_distance_raw1-editor_distance_raw3 $authorcontrols if indicate==1, absorb(editor_id) vce(cluster ms_number_id)
estadd local refFE "X",replace
estadd local paperFE " ",replace
estadd local authorcontrols "X",replace
*Everything together
eststo: reghdfe passed_the_desk editor_phdmatch_max editor_employmentmatch_max editor_isnbermatch_program_max editor_distance_raw1-editor_distance_raw3 $authorcontrols if indicate==1, absorb(editor_id) vce(cluster ms_number_id)
estadd local refFE "X",replace
estadd local paperFE " ",replace
estadd local authorcontrols "X",replace
*Number of connections
eststo: reghdfe passed_the_desk editor_Nconnections_raw2-editor_Nconnections_raw3 $authorcontrols if indicate==1, absorb(editor_id) vce(cluster ms_number_id)
estadd local refFE "X",replace
estadd local paperFE " ",replace
estadd local authorcontrols "X",replace

label var editor_phdmatch_max "At least one author \& editor: \\ \ \ -Exact same PhD institution" 
label var editor_employmentmatch_max "\ \ -Former/current colleagues"
label var editor_isnbermatch_program_max "\ \ -Same NBER program(s)"
label var editor_distance_raw1 "Shortest coauthor connection: \\ \ \ Degrees of separation: 1"
label var editor_distance_raw2 "\ \ Degrees of separation: 2"
label var editor_distance_raw3 "\ \ Degrees of separation: 3"
label var editor_Nconnections_raw2 "\hline Total \# of direct matches: \\ \ \ - One match"
label var editor_Nconnections_raw3 "\ \ - Two+ matches"

esttab using "editormatch_paperreferee.tex", ///
    replace se(3) b(3) star(* 0.10 ** 0.05 *** 0.01) nonotes noconstant nogaps noobs nonum  ///
	mgroups("Passed the desk", pattern(1 0 0 0 0 0 0 0 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))  ///
	s(N refFE authorcontrols, label("Editor-papers" "Editor FE" "Author controls (averages)") fmt(%12.0f)) ///
	mtitles("(1)" "(2)" "(3)" "(4)" "(5)" "(6)" "(7)" "(8)" "(9)" "(10)" "(11)" "(12)") label ///
	keep(editor_phdmatch_max editor_employmentmatch_max editor_isnbermatch_program_max editor_distance_raw* editor_Nconnections_raw2 editor_Nconnections_raw3)


**************
* ) Reviewers
*Employment and PhD
eststo clear
*Editor - Connectivity
eststo: reghdfe RR referee_phdmatch_max, absorb(referee_id ms_number_id) vce(cluster ms_number_id)
estadd local refFE "X",replace
estadd local paperFE " ",replace
estadd local authorcontrols "X",replace
*Editor - Connectivity
eststo: reghdfe RR referee_employmentmatch_max, absorb(referee_id ms_number_id) vce(cluster ms_number_id)
estadd local refFE "X",replace
estadd local paperFE " ",replace
estadd local authorcontrols "X",replace
*NBER program match
eststo: reghdfe RR referee_isnbermatch_program_max, absorb(referee_id ms_number_id) vce(cluster ms_number_id)
estadd local refFE "X",replace
estadd local paperFE " ",replace
estadd local authorcontrols "X",replace
*Editor - Connectivity
eststo: reghdfe RR referee_distance_raw1-referee_distance_raw3, absorb(referee_id ms_number_id) vce(cluster ms_number_id)
estadd local refFE "X",replace
estadd local paperFE " ",replace
estadd local authorcontrols "X",replace
*Everything together
eststo: reghdfe RR referee_phdmatch_max referee_employmentmatch_max referee_isnbermatch_program_max referee_distance_raw1-referee_distance_raw3, absorb(referee_id ms_number_id) vce(cluster ms_number_id)
estadd local refFE "X",replace
estadd local paperFE " ",replace
estadd local authorcontrols "X",replace
*Number of connections
eststo: reghdfe RR referee_Nconnections_raw2-referee_Nconnections_raw3, absorb(referee_id ms_number_id) vce(cluster ms_number_id)
estadd local refFE "X",replace
estadd local paperFE " ",replace
estadd local authorcontrols "X",replace

label var referee_phdmatch_max "At least one author \& reviewer: \\ \ \ -Exact same PhD institution" 
label var referee_employmentmatch_max "\ \ -Former/current colleagues"
label var referee_isnbermatch_program_max "\ \ -Same NBER program(s)"
label var referee_distance_raw1 "Shortest coauthor connection: \\ \ \ Degrees of separation: 1"
label var referee_distance_raw2 "\ \ Degrees of separation: 2"
label var referee_distance_raw3 "\ \ Degrees of separation: 3"
label var referee_Nconnections_raw2 "\hline Total \# of direct matches: \\ \ \ - One match"
label var referee_Nconnections_raw3 "\ \ - Two+ matches"

esttab using "refereematch_paperreferee.tex", ///
    replace se(3) b(3) star(* 0.10 ** 0.05 *** 0.01) nonotes noconstant nogaps noobs nonum  ///
	mgroups("Positive evaluation", pattern(1 0 0 0 0 0 0 0 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))  ///
	s(N refFE authorcontrols, label("Reviewer-papers" "Editor FE" "Paper FE") fmt(%12.0f)) ///
	mtitles("(1)" "(2)" "(3)" "(4)" "(5)" "(6)" "(7)" "(8)" "(9)" "(10)" "(11)" "(12)") label ///
	keep(referee_phdmatch_max referee_employmentmatch_max referee_isnbermatch_program_max referee_distance_raw* referee_Nconnections_raw2 referee_Nconnections_raw3)
